//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Collections;
using System.Collections.Generic;

namespace OpenLS.Spreadsheet.Collections
{
    class FrugalDictionaryCollection<TValue> : ICollection<TValue> where TValue: class
    {
        public FrugalDictionaryCollection(IFrugalDictionary<TValue> dic)
        {
            this.dic = dic;
        }
        IFrugalDictionary<TValue> dic;
        #region ICollection<TValue> Members

        public void Add(TValue item)
        {
            throw new NotSupportedException();
        }

        public void Clear()
        {
            this.dic = new SingleItemDictionary<TValue>();
        }

        public bool Contains(TValue item)
        {
            throw new NotSupportedException();
        }

        public void CopyTo(TValue[] array, int arrayIndex)
        {
            throw new NotSupportedException();
        }

        public int Count
        {
            get { return dic.Count; }
        }

        public bool IsReadOnly
        {
            get { return true; }
        }

        public bool Remove(TValue item)
        {
            throw new NotSupportedException();
        }

        #endregion

        #region IEnumerable<TValue> Members

        public IEnumerator<TValue> GetEnumerator()
        {
            foreach (int key in dic)
            {
                TValue value;
                dic.TryGetValue(key, out value);
                yield return value;
            }
        }

        #endregion

        #region IEnumerable Members

        IEnumerator IEnumerable.GetEnumerator()
        {
            return this.GetEnumerator();
        }

        #endregion
    }
}
